(function() {
  // alert(window.location.href);
  function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
      var str = url.substr(1);
      strs = str.split("&");
      for (var i = 0; i < strs.length; i++) {
        theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
      }
    }
    return theRequest;
  }
  var myurl = window.location.href;
  var openid = GetRequest().openid;
  wx.ready(function() {
    var title = "龙抬头，好运来，送壕礼！";
    var descT = "一大波2元、5元、10元、20元电子券正在等你来领~";
    var desc = "一大波2元、5元、10元、20元电子券正在等你来领~";
    var  link='http://wkfw.unisk.cn/woqianbao/longtaitou/redirect.html';
    var imgUrl = "http://wkfw.unisk.cn/woqianbao/longtaitou/images/game-gragen.png";

    //分享到朋友圈
    wx.onMenuShareTimeline({
      title: title, // 分享标题【必填】
      desc: desc, // 分享描述【必填】
      link: link, // 分享链接【必填】
      imgUrl: imgUrl, // 分享图标【必填】
      success: function() {
        // 用户确认分享后执行的回调函数
        //shareNum();
      },
      cancel: function() {
        // 用户取消分享后执行的回调函数
      }
    });

    //分享给好友
    wx.onMenuShareAppMessage({
      title: title, // 分享标题【必填】
      desc: descT, // 分享描述【必填】
      link: link, // 分享链接【必填】
      imgUrl: imgUrl, // 分享图标【必填】
      type: 'link', // 分享类型,music、video或link，不填默认为link【必填】
      dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
      success: function() {
        // 用户确认分享后执行的回调函数
        alert('已分享');
        //shareNum();
      },
      cancel: function() {
        // 用户取消分享后执行的回调函数
        alert('已取消');
      }
    });

  });

  var appId = "wx22a6154dfb9e6b4f";
  var nonceStr = "oDxlNmsjqvV9D29r"; //随意
  var timestamp = "1420942347"; //随意

  var signature = null;

  $.ajax({
    url:'http://wkfw.unisk.cn/woqianbao/getSignature',
    async: false,
    dataType: "json",
    data: {
      "noncestr": nonceStr,
      "timestamp": timestamp,
      "url": myurl
    },
    success: function(data) {
      signature=data.res;
      console.log(signature);
    },
    error: function() {
      signature = "error";
    }
  });
  wx.config({
    debug: false,
    appId: appId,
    timestamp: timestamp,
    nonceStr: nonceStr,
    signature: signature,
    jsApiList: ['checkJsApi', 'onMenuShareTimeline',
      'onMenuShareAppMessage', 'onMenuShareQQ',
      'onMenuShareWeibo', 'hideMenuItems', 'showMenuItems',
      'hideAllNonBaseMenuItem', 'showAllNonBaseMenuItem',
      'translateVoice', 'startRecord', 'stopRecord',
      'onRecordEnd', 'playVoice', 'pauseVoice', 'stopVoice',
      'uploadVoice', 'downloadVoice', 'chooseImage',
      'previewImage', 'uploadImage', 'downloadImage',
      'getNetworkType', 'openLocation', 'getLocation',
      'hideOptionMenu', 'showOptionMenu', 'closeWindow',
      'scanQRCode', 'chooseWXPay', 'openProductSpecificView',
      'addCard', 'chooseCard', 'openCard'
    ]
  });
})();
